home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / lib / xdisplayfile.pro < prev    next >
Text File  |  1997-07-08  |  4KB  |  133 lines

  1. ; $Id: xdisplayfile.pro,v 1.10 1997/01/15 03:11:50 ali Exp $
  2. ;
  3. ; Copyright (c) 1991-1997, Research Systems, Inc.  All rights reserved.
  4. ;    Unauthorized reproduction prohibited.
  5. PRO XDispFile_evt, event
  6.  
  7. WIDGET_CONTROL, GET_UVALUE = retval, event.id
  8.  
  9. IF (retval EQ "EXIT") THEN WIDGET_CONTROL, event.top, /DESTROY
  10.  
  11. END
  12.  
  13.  
  14. PRO XDisplayFile, FILENAME, TITLE = TITLE, GROUP = GROUP, WIDTH = WIDTH, $
  15.                   HEIGHT = HEIGHT, TEXT = TEXT, FONT = font, $
  16.                   DONE_BUTTON=done_button
  17. ;+
  18. ; NAME: 
  19. ;    XDISPLAYFILE
  20. ;
  21. ; PURPOSE:
  22. ;    Display an ASCII text file using widgets and the widget manager.
  23. ;
  24. ; CATEGORY:
  25. ;    Widgets.
  26. ;
  27. ; CALLING SEQUENCE:
  28. ;    XDISPLAYFILE, Filename
  29. ;
  30. ; INPUTS:
  31. ;     Filename:    A scalar string that contains the filename of the file
  32. ;        to display.  The filename can include a path to that file.
  33. ;
  34. ; KEYWORD PARAMETERS:
  35. ;    DONE_BUTTON: the text to use for the Done button.  If omitted,
  36. ;        the text "Done with <filename>" is used.
  37. ;    FONT:   The name of the font to use.  If omitted use the default
  38. ;        font.
  39. ;    GROUP:    The widget ID of the group leader of the widget.  If this 
  40. ;        keyword is specified, the death of the group leader results in
  41. ;        the death of XDISPLAYFILE.
  42. ;
  43. ;    HEIGHT:    The number of text lines that the widget should display at one
  44. ;        time.  If this keyword is not specified, 24 lines is the 
  45. ;        default.
  46. ;
  47. ;    TEXT:    A string or string array to be displayed in the widget
  48. ;        instead of the contents of a file.  This keyword supercedes
  49. ;        the FILENAME input parameter.
  50. ;
  51. ;    TITLE:    A string to use as the widget title rather than the file name 
  52. ;        or "XDisplayFile".
  53. ;
  54. ;    WIDTH:    The number of characters wide the widget should be.  If this
  55. ;        keyword is not specified, 80 characters is the default.
  56. ;
  57. ; OUTPUTS:
  58. ;    No explicit outputs.  A file viewing widget is created.
  59. ;
  60. ; SIDE EFFECTS:
  61. ;    Triggers the XMANAGER if it is not already in use.
  62. ;
  63. ; RESTRICTIONS:
  64. ;    None.
  65. ;
  66. ; PROCEDURE:
  67. ;    Open a file and create a widget to display its contents.
  68. ;
  69. ; MODIFICATION HISTORY:
  70. ;    Written By Steve Richards, December 1990
  71. ;    Graceful error recovery, DMS, Feb, 1992.
  72. ;       12 Jan. 1994  - KDB
  73. ;               If file was empty, program would crash. Fixed.
  74. ;       4 Oct. 1994     MLR Fixed bug if /TEXT was present and /TITLE was not.
  75. ;    2 jan 1997    DMS Added DONE_BUTTON keyword, made Done
  76. ;            button align on left, removed padding.
  77. ;-
  78.                                                         ;use the defaults if
  79. IF(NOT(KEYWORD_SET(HEIGHT))) THEN HEIGHT = 24        ;the keywords were not
  80. IF(NOT(KEYWORD_SET(WIDTH))) THEN WIDTH = 80        ;passed in
  81.  
  82. IF(NOT(KEYWORD_SET(TEXT))) THEN BEGIN
  83.   IF(NOT(KEYWORD_SET(TITLE))) THEN TITLE = FILENAME     
  84.   OPENR, unit, FILENAME, /GET_LUN, ERROR=i        ;open the file and then
  85.   if i lt 0 then begin        ;OK?
  86.     a = [ !err_string, ' Can not display ' + filename]  ;No
  87.   endif else begin
  88.       maxlines = 10000        ;Maximum # of lines in file
  89.       a = strarr(maxlines)
  90.       on_ioerror, done_reading
  91.       readf, unit, a
  92. done_reading: s = fstat(unit)        ;Get # of lines actually read
  93.       a = a[0: (s.transfer_count-1) > 0]
  94.       on_ioerror, null
  95.       FREE_LUN, unit                ;free the file unit.
  96.   endelse
  97. ENDIF ELSE BEGIN
  98.     IF(NOT(KEYWORD_SET(TITLE))) THEN TITLE = 'XDisplayFile'
  99.     a = TEXT
  100. ENDELSE
  101.  
  102. filebase = WIDGET_BASE(TITLE = TITLE, $            ;create the base
  103.         /BASE_ALIGN_LEFT, /COLUMN)
  104. ;        SPACE = 20, XPAD = 20, YPAD = 20)
  105.  
  106. ; Default Done button name:
  107. if n_elements(done_button) eq 0 then done_button = "Done with " + TITLE
  108. filequit = WIDGET_BUTTON(filebase, $            ;create a Done Button
  109.         VALUE = done_button, UVALUE = "EXIT")
  110.  
  111. IF n_elements(font) gt 0 then $
  112.  filetext = WIDGET_TEXT(filebase, $            ;create a text widget
  113.         XSIZE = WIDTH, $            ;to display the file's
  114.         YSIZE = HEIGHT, $            ;contents
  115.         /SCROLL, FONT = font, $
  116.         VALUE = a) $
  117. ELSE filetext = WIDGET_TEXT(filebase, $            ;create a text widget
  118.         XSIZE = WIDTH, $            ;to display the file's
  119.         YSIZE = HEIGHT, $            ;contents
  120.         /SCROLL, $
  121.         VALUE = a)
  122.  
  123.  
  124. WIDGET_CONTROL, filebase, /REALIZE            ;instantiate the widget
  125.  
  126. Xmanager, "XDisplayFile", $                ;register it with the
  127.         filebase, $                ;widget manager
  128.         GROUP_LEADER = GROUP, $
  129.         EVENT_HANDLER = "XDispFile_evt", /NO_BLOCK
  130.  
  131. END  ;--------------------- procedure XDisplayFile ----------------------------
  132.  
  133.